<?php
	
	
	$server = "192.168.0.4";
	$login = "support";
	$password = "vanilla";
  
	if (!isset($_POST["flag"])) {
		exit("<h3>For internal use with <a href=\"addimage.html\">addimage.html</a> only!");
	}
	
	
	
	foreach ($_FILES["pictures"]["error"] as $key => $error) { 
     
	    if ($error == UPLOAD_ERR_OK) {
	        $tmp_name = $_FILES["pictures"]["tmp_name"][$key];
			
			
	    }
	}

	
	
  
	if(!$data = addslashes(@fread(@fopen($tmp_name, "r"), @filesize($tmp_name)))){
		die("\n<BR>Cannot read temp file: $tmp_file"); 
	} 

 
	$link = mysql_connect($server, $login, $password);
	if (!$link) {
		die("\n<BR>Could not connect $server:" .  mysql_error());
	}
  
	$db_selected = mysql_select_db("maga");
  
	if (!$db_selected) {
		die ("\n<BR>Can\'t use Table : $db_selected" . mysql_error());
	}
  
	$query   = "INSERT INTO advertisemnt_add(adv_data) VALUES ('$data')";
    

	$result = mysql_query($query);
  
	if (!$result) {
		$message  = '<BR>Invalid query: ' . mysql_error() . "\n";
		die($message);
	}
 
  
	$image_id = mysql_insert_id() ;
  
	//printf("\n<br>Last inserted record has id %d\n",$image_id);
	
	echo '<div align="right">';
	echo "\n<BR><BR>And The Add is:";
	echo "\n<IMG SRC=\"getadd.php?id=$image_id\" />";
	echo '</div>';
	
	mysql_close($link);
  
	exit();

?>
